package ch4;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLDecoder;

@WebServlet(name = "CookieServlet2",value = "/showCookie")
public class CookieServlet2 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie[] cookies = request.getCookies ();
        for (Cookie tmp : cookies) {
            System.out.println ("cookie的名字："+tmp.getName ());
            System.out.println ("cookie的值："+tmp.getValue ());
            if (tmp.getName ().equals ("lastAccess")){
                String de_value =
                        URLDecoder.decode (tmp.getValue (),"utf-8");
                System.out.println ("lastAccess的值解码后："+de_value);
            }
        }
    }
}
